package com.scalar.forecast.projectSetup.actionCommands;

import com.scalar.forecast.actionCommands.ActionCommand;
import com.scalar.forecast.projectSetup.forms.UserDefinedFieldsForm;
import com.scalar.forecast.projectSetup.dao.UserDefinedFieldsDAO;
import com.scalar.forecast.commons.SessionKeys;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

/**
 * Process the request to load the user defined fields for project setup
 *
 * Created by Veeru. 
 * Date: Feb 9, 2005
 * Time: 8:29:59 PM 
 */


public class UserDefinedFieldsModifyCommand extends ActionCommand {

    public ActionForward execute( ActionMapping mapping,
                                  ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response ) {

        ActionForward actionForward = mapping.findForward( "userDefinedFields" );
        UserDefinedFieldsForm userDefinedFieldsForm = ( UserDefinedFieldsForm )form;

        HashMap errors = new HashMap ();
        request.setAttribute( SessionKeys.ERROR_MESSAGES, errors );

        try {
            UserDefinedFieldsDAO.loadUserDefinedFieldNames( null, userDefinedFieldsForm );
        } catch ( Exception e ) {
            e.printStackTrace();
            errors.put( "Error while loading the User Defined Fields", null );
        }

        return actionForward;
    }
}
